package com.baizhi.action;


import com.baizhi.dao.Dao;
import com.baizhi.entity.Title;
import com.baizhi.util.JDBCUtil;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * description:
 *
 * @author RenShiWei
 * Date: 2021/1/4 16:28
 **/
@WebServlet("/SlurAllServlet")
public class blogJsonServlet extends HttpServlet {
    private JdbcTemplate template = new JdbcTemplate(JDBCUtil.getDataSource());
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.设置编码
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        //2.设置响应数据类型为json
        String str=request.getParameter("str");

        Dao d = new Dao();
        HttpSession session=request.getSession();
        List<Title> mybloglist1=d.querryslurall(str);
        System.out.println("str"+str);
        System.out.println("myblogList"+mybloglist1);
        session.setAttribute("titles",mybloglist1);
        response.sendRedirect(request.getContextPath()+"/blog.jsp");

    }
}